<template>
	<view class="content">
		<!-- <view class="search-block block">
			<CustomNav :isBack="true" :keyword="keyword" :custom="custom"></CustomNav>
		</view> -->
		<view class="block screen-block">
			<view class="screen-item">
				<picker :range="category" @change="bindCategory" range-key="typeName" class="picker category">
					{{category[categoryActive]?category[categoryActive].typeName:''}}
				</picker>
				<view class="iconfont icon-xiasanjiaoxing"></view>
			</view>
			<view class="screen-item">
				<picker :range="businessArea" @change="bindBusinessArea" range-key="shoppingName"
					class="picker businessArea">
					{{businessArea[businessAreaActive]?businessArea[businessAreaActive].shoppingName:''}}
				</picker>
				<view class="iconfont icon-xiasanjiaoxing"></view>
			</view>
			<!-- <view class="screen-item">
				<view :class="optionActive==1?'active':''" @click="bindOption(1)" class="option">离我最近</view>
			</view>
			<view class="screen-item">
				<view :class=" optionActive==2?'active':''" @click="bindOption(2)" class="option">好评优先</view>
			</view> -->
		</view>
		<!-- <view class="block label-block">
			<view v-for="(item,index) in label" :key="item.id" @click="keyword=item.value" class="label-item">
				{{item.value}}
			</view>
		</view> -->
		<view class="block list-block">
			<navigator hover-class="none" :url="'/pages/attractions/tickets?id='+item.id" v-for="(item,index) in list"
				:key="item.id" class="list-item attractions">
				<image mode="aspectFill" :src="item.picUrl" class="photo"></image>
				<view class="info-block">
					<view class="name">{{item.title}}</view>
					<view class="ranking-block">
						<view class="ranking">
							<view class="iconfont icon-diamond"></view>酒泉人气排行第{{item.viewList}}名
						</view>
						<view class="position">
							<view class="iconfont icon-dingweixiao"></view><!-- {{item.distance}} -->1.7km
						</view>
					</view>
					<view class="score-block">
						<view class="score-name">评分:</view>
						<view class="score">{{item.score}}</view>
						<view class="score-num">{{item.comNum}}评价</view>
						<!-- <view class="business-area">暂无</view> -->
					</view>
					<view v-if="item.price" class="price">￥{{item.price}}起</view>
					<view v-else-if="item.price==0" class="price free">{{item.free}}</view>
					<!-- <view v-else class="price free">暂无报价</view> -->
				</view>
			</navigator>
		</view>
	</view>
</template>

<script>
	import {
		postListApi,
		getViewListApi,
		getShoppingListApi,
		getFindAllLikes
	} from '@/api/attractions.js';
	export default {
		data() {
			return {
				keyword: '',
				custom: null,
				category: [],
				categoryActive: 0,
				businessArea: [],
				businessAreaActive: 0,
				optionActive: 0,
				list: [],
				categoryActiveId: 0,
				businessAreaActiveId: 0,

			}
		},
		methods: {
			bindCategory(e) {
				this.categoryActive = e.detail.value;
				this.getList();
			},
			bindBusinessArea(e) {
				this.businessAreaActive = e.detail.value;
				this.getList();
			},
			// bindOption(index) {
			// 	this.optionActive = index;
			// },
			//景点门票列表
			getList() {
				// uni.showLoading({
				// 	title: '加载中',
				// 	mask: true,
				// })
				if (this.category != null && this.category.length > 0) {
					this.categoryActiveId = this.category[this.categoryActive].id;
				}
				if (this.businessArea != null && this.businessArea.length > 0) {
					this.businessAreaActiveId = this.businessArea[this.businessAreaActive].id;
				}
				postListApi({
					viewType: this.categoryActiveId,
					shopping: this.businessAreaActiveId,
					sortType: this.optionActive,
					page: 0,
					limit: 0
				}).then((res) => {
					if (res.code == 1) {
						this.list = res.data
					} else {
						uni.showToast({
							title: '加载失败',
							mask: true,
						})
					}
				}).catch((res) => {
					console.log(res)
				})
			},
			//查询全部分类
			getViewList() {
				// uni.showLoading({
				// 	title: '加载中',
				// 	mask: true,
				// })
				getViewListApi().then((res) => {
					if (res.code == 1) {
						this.category = res.data;
						this.categoryActive = 0;
					} else {
						uni.showToast({
							title: '加载失败',
							mask: true,
						})
					}
				}).catch((res) => {
					console.log(res)
				})
			},
			//商圈类型
			getShoppingList() {
				// uni.showLoading({
				// 	title: '加载中',
				// 	mask: true,
				// })
				getShoppingListApi({}).then((res) => {
					if (res.code == 1) {
						this.businessArea = res.data;
						this.businessAreaActive = 0;
						this.getList();
					} else {
						uni.showToast({
							title: '加载失败',
							mask: true,
						})
					}
				}).catch((res) => {
					uni.hideLoading();
					console.log(res)
				})
			},
			//模糊查询
			getSearchList() {
				let title = this.title
				getFindAllLikes({
					title
				}).then((res) => {
					if (res.code === 1) {
						this.list = res.data;
						console.log(this.list)
					} else {
						console.log(res)
					}
				}).catch((res) => {
					console.log(res)
				})
			},
		},
		mounted(e) {
			/*自适应微信胶囊按钮*/
			this.custom = this.utils.getCustomNavData();
		},
		onLoad() {
			uni.$on('getSearchInput', (e) => {
				this.title = e;
			})
			this.getViewList();
			this.getShoppingList();
		}
	}
</script>

<style lang="scss">
	.content {
		.block.search-block {
			background: $color-primary;
			overflow: hidden;
		}

		.block.screen-block {
			display: flex;
			flex-direction: row;
			background: $color-primary;
			align-items: center;
			padding: 20rpx;

			.screen-item {
				display: flex;
				justify-content: center;
				color: $color-border-lighter;
				align-items: center;
				font-size: 30rpx;
				flex-grow: 1;

				.picker {
					display: flex;
					justify-content: center;
				}

				.picker.category {
					font-weight: bold;
					font-size: 34rpx;
					color: #fff;
				}

				.picker.businessArea {
					font-weight: bold;
					font-size: 34rpx;
					color: #fff;
				}

				.iconfont {
					margin-left: 16rpx;
					font-size: 28rpx;
					font-weight: normal;
				}

				.option.active {
					font-weight: bold;
					font-size: 34rpx;
					color: #fff;
				}
			}
		}

		.block.label-block {
			display: flex;
			flex-direction: row;
			overflow-x: scroll;
			width: 100%;
			padding: 20rpx 0;

			.label-item {
				border-radius: 30rpx;
				color: $color-regular-text;
				font-size: 26rpx;
				padding: 10rpx 30rpx;
				background: $color-border-extralight;
				margin: 0 10rpx;
				flex: none;
			}
		}

		.block.list-block {
			padding: 0 30rpx;
			display: flex;
			flex-direction: column;

			.list-item.attractions {
				display: flex;
				flex-direction: row;
				padding: 30rpx 0;
				border-bottom: 1px solid #efefef;

				.photo {
					width: 220rpx;
					height: 180rpx;
					border-radius: 12rpx;
					margin-right: 20rpx;
				}

				.info-block {
					width: calc(100% - 240rpx);
					display: flex;
					flex-direction: column;

					.name {
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						font-weight: bold;
						font-size: 34rpx;
						margin-bottom: 10rpx;
					}

					.ranking-block {
						display: flex;
						font-size: 24rpx;
						align-items: center;
						flex-direction: row;
						margin-top: 10rpx;

						.ranking {
							display: flex;
							flex-direction: row;
							background: #FEE7CF;
							color: #AB6B45;
							padding: 5rpx 10rpx;
							border-radius: 8rpx;

							.iconfont {
								margin-right: 8rpx;
							}
						}

						.position {
							.iconfont {
								margin-right: 8rpx;
							}

							display: flex;
							flex-direction: row;
							flex-grow: 1;
							justify-content: flex-end;
							color: $color-secondary-text;
						}
					}

					.score-block {
						display: flex;
						align-items: center;
						margin-top: 10rpx;

						.score-name {}

						.score {
							flex-grow: 0;
							font-size: 34rpx;
							font-weight: bold;
							margin-right: 14rpx;
							background: url('@/static/bottom.png') no-repeat;
							background-position: center 85%;
							background-size: 80%;
						}

						.score-num {
							flex-grow: 0;
							font-size: 24rpx;
							color: $color-secondary-text;
						}

						.business-area {
							flex-grow: 1;
							font-size: 26rpx;
							color: $color-secondary-text;
							text-align: right;
						}
					}

					.price {
						font-weight: bold;
						color: $color-danger;
					}

					.price.free {
						font-weight: normal;
						color: $color-secondary-text;
					}
				}
			}

			.list-item.attractions:last-child {
				border: none;
			}
		}
	}
</style>